package jml.defaultimple.util;

import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import org.imgscalr.Scalr;
import org.imgscalr.Scalr.Mode;

public class UImage
{
	public static void makeScaledImage(String fromFullname,int width, int height, OutputStream oos)
	{
		try
		{
			BufferedImage i = ImageIO.read(new File(fromFullname));
			System.setProperty(Scalr.DEBUG_PROPERTY_NAME, "false");
			
			ImageIO.write(Scalr.resize(i, Mode.FIT_EXACT, width, height), "PNG", new BufferedOutputStream(oos));
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	
	public static void makeScaledImage(String fromFullname,String toFullname,int width, int height)
	{
		try
		{
			BufferedImage i = ImageIO.read(new File(fromFullname));
			System.setProperty(Scalr.DEBUG_PROPERTY_NAME, "false");
			
			ImageIO.write(Scalr.resize(i, Mode.FIT_EXACT, width, height), "JPG", new BufferedOutputStream(new FileOutputStream(toFullname)));
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
		
	public static void main(String[] args)
	{
		makeScaledImage("folder.jpg", "folder_out.jpg", 120, 120);
	}
}
